package com.example.gui;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import com.example.data.AllData;
import com.google.android.material.bottomnavigation.BottomNavigationView;

public class UserActivity extends AppCompatActivity {
    private TextView nameTextView;
    private UserActivity self = this;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user);

        AllData data = (AllData) getApplication();

        nameTextView = findViewById(R.id.nameTextView);
        nameTextView.setText(data.getAccount());





        OptionItemView settingOptionItemView = findViewById(R.id.settintOptionItemView);
        settingOptionItemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(UserActivity.this);
                builder.setTitle("提示");
                builder.setMessage("该功能尚未完成");
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                builder.show();
            }
        });

        //找到导航栏
        BottomNavigationView bottomNavigationView = findViewById(R.id.bottomNavigationView);

        bottomNavigationView.getMenu().findItem(R.id.me).setChecked(true);

        bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                // 处理每个选项的点击事件
                int itemId = item.getItemId();
                if (itemId == R.id.conversation_list) {
                        // 获取当前显示的 Activity
                            Intent intent = new Intent(self, HomeActivity.class);
                            startActivity(intent);
                        overridePendingTransition(0, 0); // 取消Activity转场动画
                    // 处理对话列表的点击事件，执行相应的页面跳转或页面切换操作
                } else if (itemId == R.id.contact) {
                    String a = "功能未开发";
                    SetMessage(a);
                    // 处理通讯录的点击事件
                } else if (itemId == R.id.setpost) {
                    Intent intent2 = new Intent(self, SetPostActivity.class);
                    startActivity(intent2);
                    // 处理发帖的点击事件
                } else if (itemId == R.id.discovery) {
                    Intent intent2 = new Intent(self, ComputerActivity.class);
                    startActivity(intent2);
                    overridePendingTransition(0, 0); // 取消Activity转场动画
                    // 处理小程序的点击事件
                } else if (itemId == R.id.me) {
                    Intent intent2 = new Intent(self, UserActivity.class);
                    startActivity(intent2);
                    overridePendingTransition(0, 0); // 取消Activity转场动画
                    // 处理我的的点击事件
                }
                return true; // 返回 true 表示消费了该事件，返回 false 则表示未消费
            }
        });


    }

    private void SetMessage(String ms){
        AlertDialog.Builder builder = new AlertDialog.Builder(self);
        builder.setTitle("提示")
                .setMessage(ms)
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                    }
                })
                .create()
                .show();
    }
}